<?php

namespace app\controllers;

use app\base\BaseController;
use app\base\BaseService;
use app\lib\Common;
use Yii;

use app\lib\Seccode;
use app\lib\Qrcode;
use app\lib\Trace;
/**
 * 生成二维码
 **/
class ImgController extends BaseController
{
    /**
     * 生成图片验证码
     *
     * @return array
     **/
    public function actionCode()
    {
        $imgCode = Common::getRandNumStr(4);//随机数字字符串
        $session = Yii::$app->session;
        $session->set('imgCode' , $imgCode);
        $code = new Seccode;
        $code->code = $imgCode;
        $code->display();
    }

    /**
     * 校验图片验证码
     *
     **/
    public function actionCheck()
    {
		$request = Yii::$app->request;
		$code = $request->post("code") ;
        if(!empty($code)) {
            $session = Yii::$app->session;
            $imgCode = $session->get('imgCode');
            if($code != $imgCode) {
                BaseService::returnErrData([], 50045, '验证码输入有误');
            }
            $session->set('imgCode' , '');
            BaseService::returnOkData([]);
        }
        BaseService::returnErrData([], 50044, '验证码不能为空');
    }
}
